home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-08-25 | 9.6 KB | 262 lines | [TEXT/CWIE] |
- ========================================================================
- PP Standard Dialogs
- ========================================================================
-
- Version: PowerPlant 1.9.2
- Date: August 19, 1998
- ========================================================================
-
- Navigation Services is a new piece of System software that provides
- dialogs for opening and saving files. Nav Services is an improvement
- on Standard File. Nav Services dialogs are moveable modal and have an
- interface similar to that of Finder list views.
-
- Nav Services ships as a separate extension for Mac OS 8.1, but will
- be part of Mac OS 8.5 (Allegro). Furthermore, Apple has stated that
- Mac OS X (Carbon) will not support Standard File. Therefore, you
- must update your programs to use Nav Services instead of Standard
- File to be Carbon-compatible. For more information, you should
- go to Apple's web site at <http://developer.apple.com/sdk/>
- and download the Navigation Services SDK.
-
- The files in the "Standard Dialogs" implement a common API for
- using both Navigation Services and Standard File.
-
-
- ========================================================================
- New Modules
- ========================================================================
-
- There are three new modules:
-
- UClassicDialogs - Always uses Standard File
- UNavServicesDialogs - Always uses Nav Services
- UConditionalDialogs - Use Nav Services if available,
- otherwise use Standard File
-
- Each module implements the exact same functions and classes, but
- wrapped in a namespace to avoid name collisions. This means that
- client code for using each module is the same except for the
- namespace name.
-
- To allow switching between modules without having to change
- client code, PowerPlant declares a PP_StandardDialogs namespace
- alias that's controlled by a preprocessor symbol. Look at
- PP_Macros.h and UStandardDialogs.h to see how the preprocessor
- symbol PP_StdDialog_Option determines the namespace to which
- the alias refers and selects the proper module.
-
- As an example, consider the following code:
-
- bool
- LDocument::AskConfirmRevert()
- {
- Str255 docName;
-
- return PP_StandardDialogs::AskConfirmRevert(GetDescriptor(docName));
- }
-
- Depending on the declaration of PP_StandardDialogs, the actual
- function called is one of:
-
- UClassicDialogs::AskConfirmRevert()
- UNavServicesDialogs::AskConfirmRevert()
- UConditionalDialogs::AskConfirmRevert()
-
- Conceptually, a namespace alias is similar to using preprocessor
- symbol substitution:
-
- #define PP_StandardDialogs UClassicDialogs
-
- rather than:
-
- namespace PP_StandardDialogs = UClassicDialogs
-
- However, the namespace alias is safer, since it won't interfere
- with the (unlikely) use of the name PP_StandardDialogs in
- another context.
-
- Note that the functions in UClassicDialogs and UNavServicesDialogs
- are completely independent. They are do not inherit from a common
- base class. The functions in UConditionalDialogs are also unrelated
- to the others by inheritance, but they do call the functions in
- the other two modules.
-
- The window titles for the Open and Save dialogs using NavServices
- are stored in strings 3 and 4 in 'STR#' 200. Existing programs
- use strings 1 and 2 in this resource are the application name and
- the "save as" prompt for StandardFile. If you do not add these
- strings, you will get the system default window titles. See the
- "PP Copy & Customize.ppob" file for an example.
-
-
- ========================================================================
- Module Format
- ========================================================================
-
- Each module implements the following functions:
-
- Load Preload necessary system facilities
- Unload Unload system facilities
-
- AskSaveChanges Ask to save changes before closing/quitting
- AskConfirmRevert Confirm revert to last saved version
-
- AskOpenOneFile Ask to select one file to open
- AskChooseOneFile Ask to select one file (not a document to open)
- AskChooseFolder Ask to select a folder
- AskChooseVolume Ask to select a volume
- AskSaveFile Ask to specify a file for saving a document
-
- Note that these functions are within the module namespace, but not
- within any class. Without namespaces, it's common to use a class
- with all static functions to logically group functions and avoid
- polluting the global scope. The PP UTextTraits class does this.
-
- With namespaces, there's no need to make a class just to group
- functions. You just put the functions in a namespace. However,
- the syntax to access the functions remains the same. For example,
-
- class Foo { // Old way. Class with
- static void Bar(); // static functions.
- static void Car();
- };
-
- Foo::Bar(); // Call function Bar in class Foo
-
-
- namespace Foo { // New way. Put functions
- void Bar(); // in a namespace.
- void Car();
- }
-
- Foo::Bar(); // Call function Bar in namespace Foo
-
-
- LDocument uses the AskSaveChanges and AskConfirmRevert functions
- to display the standard dialogs to ask the user to confirm an
- action which may discard data.
-
- The other "ask" functions are simple routines for letting the
- user choose or specify a file. They are similar to StandardGetFile
- and StandardPutFile.
-
- LDocument::AskSaveAs calls AskSaveFile to ask the user to specify
- a file for saving the document.
-
- To support all the extra options and features that Nav Services
- offers beyond Standard File, each module also implements two
- helper classes:
-
- LFileChooser Helper class for choosing files to open
-
- LFileDesignator Helper class for designating a file for
- saving a document
-
- The Classic versions of these are equivalent to the simple
- "ask" functions above. The NavServices versions retain options
- and state information that allow you to customize the dialogs
- and to use the automatic file translation features.
-
-
- ========================================================================
- New Files
- ========================================================================
-
- UStandardDialogs.h
- Common header file for all modules. #include this header
- in your source files.
-
- UClassicDialogs.h
- UClassicDialogs.cp
- Header and source for UClassicDialogs. Add the .cp file
- to your project if you use the classic or conditional
- dialogs option.
-
- UNavServicesDialogs.h
- UNavServicesDialogs.cp
- Header and source for UNavServicesDialogs. Add the .cp
- file to your project if you use the Nav Services or
- conditional dialogs option.
-
- UConditionalDialogs.h
- UConditionalDialogs.cp
- Header and source for UConditionalDialogs. Add the .cp
- file to your project if you use the conditional dialogs
- option.
-
- UStandardDialogs.i
- Declarations of common functions. #include'd by the
- header for each module. This avoids have to put the
- same function prototypes in each of the three headers.
-
- LFileChooser.i
- Declaration of the LFileChooser class. #include'd by
- header for each module. This avoids have to put the
- same class declaration in each of the three headers.
-
- LFileDesignator.i
- Declaration of the LFileDesignator class. #include'd by
- header for each module. This avoids have to put the
- same class declaration in each of the three headers.
-
-
- ========================================================================
- Using the Modules
- ========================================================================
-
- The "TextDoc Demo" program has examples of using the modules.
-
- The "ask" functions are the easiest to use. They all pass back
- the FSSpec of the file selected by the user. See LDocument::AskSaveAs()
- and CTextViewDemoApp::DoInsertFile() for examples.
-
- CTextViewDemoApp::ChooseDocument() demonstates using LFileChooser
- as a stack-based object, which will be its most common usage.
- You might want to store an LFileChooser object if you wish to
- specify some custom options that you can re-use when you open
- particular kinds of files.
-
- The CTextDoc class stores a LFileDesignator object and uses it
- when asking the user to save a file. Storing a LFileDesignator
- lets you use Nav Services to translate a file in an efficient
- manner. Consider this scenario:
-
- (1) User creates a new document and enters data
- (2) User chooses "save". LFileDesignator calls NavPutFile to
- let the user specify a new file. In doing so, the
- user also chooses a file format which requires translation.
- (3) Your program saves the document in its native format and
- not the format selected by the user.
- (4) User enters more data and chooses "save"
- (5) Your program saves the document in its native format
- (6) Steps 4 and 5 repeat as user continues to work on the document
- (7) User closes document
- (8) If document has changed since last save, you prompt user to
- save the changes. If user chooses to save, you again save
- the document in its native format
- (9) Finally, the destructor for LFileDesignator calls
- NavCompleteSave to translate the document into the format
- the user selected in step 2.
-
- By defering the translation until step 9, we avoid having to
- translate the document each time the user performed an intermediate
- save in step 4. Depending on the file formats, translation can
- be time consuming. This would be very annoying for users who
- frequently save documents while working.
-
- However, defering the translation means that we need to store
- information from the initial save dialog until the document
- closes. Thus, we need to store the LFileDesignator object
- rather than using a stack-based object or a simple function call.
-
-
- ========================================================================
- Known Limitations
- ========================================================================
-
- * Setting the default location to a Volume does not work using
- Classic Dialogs. The problem seems to be that Standard File
- presents the illusion that volumes are contained within
- the Desktop. In reality, the Desktop is an invisible folder
- within the root volume.